﻿var Drag = {
    obj: null,
    init: function(a, b, c) {
        var d, e;
        null == c && (a.onmousedown = Drag.start), a.root = b, isNaN(parseInt(a.root.style.left)) && (a.root.style.left = "0px"), 
        isNaN(parseInt(a.root.style.top)) && (a.root.style.top = "0px"), a.root.onDragStart = new Function(), 
        a.root.onDragEnd = new Function(), a.root.onDrag = new Function(), null != c && (a = Drag.obj = a, 
        c = Drag.fixe(c), d = parseInt(a.root.style.top), e = parseInt(a.root.style.left), 
        a.root.onDragStart(e, d, c.pageX, c.pageY), a.lastMouseX = c.pageX, a.lastMouseY = c.pageY, 
        document.onmousemove = Drag.drag, document.onmouseup = Drag.end);
    },
    start: function(a) {
        var c, d, b = Drag.obj = this;
        return a = Drag.fixEvent(a), c = parseInt(b.root.style.top), d = parseInt(b.root.style.left), 
        b.root.onDragStart(d, c, a.pageX, a.pageY), b.lastMouseX = a.pageX, b.lastMouseY = a.pageY, 
        document.onmousemove = Drag.drag, document.onmouseup = Drag.end, !1;
    },
    drag: function(a) {
        var b, c, d, e, f, g, h;
        return a = Drag.fixEvent(a), b = Drag.obj, c = a.pageY, d = a.pageX, e = parseInt(b.root.style.top), 
        f = parseInt(b.root.style.left), document.all ? Drag.obj.setCapture() : a.preventDefault(), 
        g = f + d - b.lastMouseX, h = e + (c - b.lastMouseY), b.root.style.left = g + "px", 
        b.root.style.top = h + "px", b.lastMouseX = d, b.lastMouseY = c, b.root.onDrag(g, h, a.pageX, a.pageY), 
        !1;
    },
    end: function() {
        document.all && Drag.obj.releaseCapture(), document.onmousemove = null, document.onmouseup = null, 
        Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style.left), parseInt(Drag.obj.root.style.top)), 
        Drag.obj = null;
    },
    fixEvent: function(a) {
        var b = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft), c = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
        return "undefined" == typeof a && (a = window.event), "undefined" == typeof a.layerX && (a.layerX = a.offsetX), 
        "undefined" == typeof a.layerY && (a.layerY = a.offsetY), "undefined" == typeof a.pageX && (a.pageX = a.clientX + b - document.body.clientLeft), 
        "undefined" == typeof a.pageY && (a.pageY = a.clientY + c - document.body.clientTop), 
        a;
    }
};